﻿using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.Mvc;
using System.Xml;
using System.Xml.Serialization;
using Isaac.Joy.Identity.Web.DtCms.ExtensionObjects;
using Isaac.Joy.Serialize;
using Newtonsoft.Json;

namespace Isaac.Joy.Identity.Web.DtCms.Controllers
{
    public class LoginController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.ReturnUrl = "/home/base";
            if (Activator.BundleContext != null)
            {
                var exts = Activator.BundleContext.GetExtensions("Isaac.Joy.Identity.Config");

                if (exts.Count >= 0)
                {
                    if (exts[0].Data.Count >= 0)
                    {
                        var config = XmlSerializable.Deserialize<Config>(exts[0].Data[0]);
                        ViewBag.ReturnUrl = config.ReturnUrl;
                    }
                }
            }
            return View();
        }

        public ActionResult AuthorizeUser(string loginid, string pwd)
        {
            return Content(JsonConvert.SerializeObject(new
            {
                return_code = 0,
                success = true
            }));
        }
    }
}
